﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DataAccess.Classes;

public partial class Admin_EditBill : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
            PopulateControls();
    }
    private void PopulateControls()
    {
        string cid = Request.QueryString["cid"] ?? "";
        if (cid != "")
        {
            // Lay  theo gia tri cid
            lblTitle.Text = "Bill " + cid;
            int ma = int.Parse(cid);
            repBill.DataSource = BillDetail.All(ma);
            repBill.DataBind();
            lblTotal.Text = BillDetail.TotalAmount(int.Parse(cid));
        }
        else
        {
            
        }
    }

    protected override void OnInit(EventArgs e)
    {
        base.OnInit(e);
        btnDelete.Click += new EventHandler(btnDelete_Click);
        btnPay.Click += new EventHandler(btnPay_Click);
    }

    void btnDelete_Click(object sender, EventArgs e)
    {
        int cid = int.Parse(Request.QueryString["cid"] ?? "");
        string stringid = Request.Form["cid"] ?? "";
        if (stringid != "")
        {
            foreach (string id in stringid.Split(','))
                BillDetail.Delete(cid, id);
            PopulateControls();
        }
    }
    void btnPay_Click(object sender, EventArgs e)
    {
        string cid = Request.QueryString["cid"] ?? "";
        Bill.Pay(cid);
        Response.Redirect("~/Cart.aspx");
    }
}